Paging IO IRP_MJ_WRITE Size

Sorry if this has been answered before, I could not find a good answer
in archives.

Paging IO write writes full sectors. If file size is 4 bytes it would
still write 4096 bytes (irpSp->Parameters.Write.Length).
I don’t want to do extra work encrypting zeroes that are not part of
file data in my crypto filter driver.
So how do I get the usable data size before the IoCallDriver() call?

Thanks.

The File size is stored in the FCB.
Underlying file system will not write more than the FileSize
(Some file systems will not write more than ValidDataLength)
in the FCB.

L.

ValidDataLength works fine most of the time.

I wrote a test application, that uses CreateFile() with
FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH flags to write file.
When I write file this way, ValidDataLength and FileSize in
IRP_MJ_WRITE dispatch is 0, but irpSp->Parameters.Write.Length is the
real length.

The code from IRP_MJ_WRITE dispatch (that apparently does not work in
this scenario):

PFSRTL_ADVANCED_FCB_HEADER Fcb;
LARGE_INTEGER Size, Offset;
ULONG Length;

Length = irpSp->Parameters.Write.Length;
Offset.QuadPart = irpSp->Parameters.Write.ByteOffset.QuadPart;
// Calculate remaining file size
Fcb = irpSp->FileObject->FsContext;
Size.QuadPart = Fcb->ValidDataLength.QuadPart - Offset.QuadPart;
// Calculate relevant write size
Length = Size.HighPart == 0 && Size.LowPart < Length ?
Size.LowPart : Length,

On Tue, 1 Mar 2005 16:30:50 +0100, Ladislav Zezula wrote:
> The File size is stored in the FCB.
> Underlying file system will not write more than the FileSize
> (Some file systems will not write more than ValidDataLength)
> in the FCB.

> I wrote a test application, that uses CreateFile() with

FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH flags to write file.

If you open a file using these flags, the write requests will
become non-cached, but not PAGING_IO.
This is the difference.

Note that you must not write a testprogram for such experiments,
download the “FileTest” tool from www.osronline.com.
It does exactly what you need.

L.

On Thu, 10 Mar 2005 11:39:02 +0100, Ladislav Zezula wrote:
> > I wrote a test application, that uses CreateFile() with
> > FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH flags to write file.
>
> If you open a file using these flags, the write requests will
> become non-cached, but not PAGING_IO.
> This is the difference.

Are you saying that ValidDataLength stuff is good only for IRP_PAGING_IO?

> Are you saying that ValidDataLength stuff is good only for

IRP_PAGING_IO?

No. I’m saying that for PAGING_IO, the number of bytes will be
truncated to FileSize (or for ValidDataLength on some file systems).

The write scenario usually works this way

  1. A cached write comes to the FSD. The FileSize and
    ValidDataLength will be updated, if the write goes past
    the end of the file.

  2. File system will issue some cache-writing function (e.g.
    CcCopyWrite)

  3. Later, when the cache manager lazily flushes the file, it will
    send a paging write request. The File system will write the data
    up to FileSize, adjusted in the step 1).

L.

File system tracks in ValidDataLength the biggest offset at which data were
written to the file by user. It allows to implement optimisation of both read
and write requests.
For read requests file system can fill part of the output buffer that lies
beyond ValidDataLength with 0s without reading data from disk.
Cache manager generates write requests in page size granularity. A part of
the page that is beyond ValidDataLength doesn’t contain any usfull data so
file system may truncate actual write request if the request is originated by
the Cache Manager. If the write request comes from user or from Modifed Page
Writer then it contains user’s information and ValidDataLength must be
extended.

Alexei.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Kriloff
Sent: Thursday, March 10, 2005 2:58 AM
To: Windows File Systems Devs Interest List
Subject: Re: [ntfsd] Paging IO IRP_MJ_WRITE Size

On Thu, 10 Mar 2005 11:39:02 +0100, Ladislav Zezula wrote:
> > I wrote a test application, that uses CreateFile() with
> > FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH flags to write file.
>
> If you open a file using these flags, the write requests will
> become non-cached, but not PAGING_IO.
> This is the difference.

Are you saying that ValidDataLength stuff is good only for IRP_PAGING_IO?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@vmware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com